/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import bean.Cliente;
import bean.Usuario;
//import com.sun.xml.internal.messaging.saaj.packaging.mime.util.QDecoderStream;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import main.Main;

/**
 *
 * @author yulian
 */
public class ProgBarHandler extends Thread{
    
    public boolean life;
    private int order;
    private int prog;
    private JProgressBar progBar;
    
    public ProgBarHandler(Object in){
        this.progBar=(JProgressBar)in;
        this.life=true;
        this.prog=0;
    }
    public boolean getLife(){
        return life;
    }
    public void kill(){
        this.life = false;
        this.progBar.setValue(0);
    }
    public void setProg(int in){this.prog=in;}
    public void setOrder(int in){   //Permite que el hilo siga en 
                                    //progreso o se detenga
        this.order = in;
    }
    @Override
    public void run(){
        while(life){
            if(order==1){
                System.out.println("Thread running.."+this.prog);
                this.prog++;
                this.progBar.setValue(this.prog);
                try{
                    Thread.sleep(10);
                }catch(Exception e){e.printStackTrace();}
            }
            if(this.prog==100){
                life = false;
                System.out.println("Thread ended..");
            }
        }  
        String id   =   Main.log.getPanelLogin1().idUsuario;
        String n    =   Main.log.getPanelLogin1().n;
        int out     =   Main.log.getPanelLogin1().out;
              
            if (out==1){
                
                 if (!Main.log.getPanelLogin1().getPGB().getLife()) {
                
                 Usuario u=Main.service.queryByUsuario(id);
                 JOptionPane.showMessageDialog(null,"Bienvenido "+u.getNombre()+" "+u.getApellidoP()+" "+u.getApellidoM()," ",JOptionPane.CLOSED_OPTION);
                 Main.principal.setVisible(true);
                 Main.log.setVisible(false);          
                 
                } 
            }
    }
}
